#ifndef GlobalsH
#define GlobalsH

  #define _free( x ) if ( x ) { free( x ); x = NULL; }
  #define WGET(x, y) *(WORD *)&x[y]
  #define CheckMSG( ) Application->ProcessMessages( )

  #define LRAM( x ) *(LONG *)&ram[ x ]
  #define WRAM( x ) *(WORD *)&ram[ x ]


  #include <vcl.h>
  #include <stdio.h>
  #include <conio.h>
  #include <stdlib.h>
  #include <string.h>
  #include <dir.h>
  #include <ctype.h>  


  typedef struct _REGZ
  { //
    WORD x;
    WORD y;
    WORD a;
    BYTE stack;
  } TREG;

  typedef struct _TFRM
  { //
    LONG lpFontOffset;
    LONG EndofText; 
    WORD cpl;
    BYTE height;
    BYTE width;
    BYTE bpp;
    BYTE inc;
    BYTE set[4];
  } TMAP;

  typedef struct TEXTBUF
  { //
    long posi;
    long ptr_posi;
    long ptr_index;
    long tpos;
    LONG rom_posi;
    WORD pntr;
    WORD data;
    WORD ypos;
    WORD xpos;
    WORD Max_ptrs;
    BYTE tile[256];
//    WORD *TextBuf;
    BYTE *TextBuf;
    BYTE tColor;
    BYTE index;
    BYTE ColorCount;
  } TBUF;

  typedef struct TMENUMAP
  {
     BYTE menu[128][128];
     WORD Ydim,
          Xdim,
          Ypos,
          Xpos;
  } TMEN;

  typedef struct _CODE
  { //
    WORD length;
    BYTE color;
    BYTE type;
    BYTE *text;
  } CODE;

  typedef struct TTEXTBOX
  {
     WORD *pic;//[0x300*304];
     WORD Ypos,
          Xpos,
          width,
          height;
  } TBOX;

  typedef struct TROMDATA
  {
    LONG Length;
    BYTE *data;
    bool Modified;
  } TROM;

  typedef struct TPTRDATA
  {
    LONG pointer;
    LONG Length;
    LONG Position;
    BYTE *Buffer;
  } TPTR;

  typedef struct TTABLEDATA
  {
    char *tbl[0x00100];
    char *dte[0x00100];
    char *dbl[0x00100];
  } TTBL;

  typedef struct PATCHER
  {
    long lof,
         ofs;
    WORD sze;
    BYTE dat;
    char fil[260];
    char rfl[260];
    BYTE *rom;
  } TPAT;


  extern LONG lpTxtBlocks[0x1000];
  extern LONG lpTxtPoints[0x1000];
  extern LONG lpPointSize[0x1000];
  extern LONG lpTxtMaxPos[0x1000];

  extern Graphics::TBitmap *Vga;
  extern char dirc[512];
  extern char txtf[512];
  extern char romf[512];
  extern char tblf[512];
  extern char cur_dir[MAXPATH];
  //
  extern long FoundAt;
  extern WORD *ScrBuf;
  extern BYTE *ram;
//  extern BYTE *rom;
  extern BYTE *tiles;
  extern TMAP map;
  extern TBUF txt;
  extern TBOX textbox[2];
  extern TROM rom;
  extern TREG reg;
  extern TMEN men;
  extern TPAT ips;  
  extern TTBL table;
  extern LONG cur_str;

  extern int  StartPos;
  extern int  ToEnd;
  extern int  curLine;
  extern int  indexLine;
  extern int  WinX;
  extern int  WinY;
//  extern BYTE EStr[0x1000];
  extern BYTE *EStr;//[0x1000];
  extern CODE codes[0x00100];
  extern CODE duals[0x10000];  
  extern bool cnDraw;
  extern bool isActive;  

  extern void Dec2Bin( BYTE *string, LONG valu, BYTE size, char type );
  extern void MenuMap( WORD *Dest, TMEN *map, int Width, bool type );
  extern void memcpyw( WORD *wsDest  , WORD *wsSrce, long lcSize, char type );
  extern void memsetw( WORD *wsBuffer, WORD wsData , long lcSize );
  extern void puttile( WORD *Dest, WORD *Srce, char y, char x, int Width, bool mask );

  extern LONG GetIndex( char *strg );  
  extern LONG Snes2Pc( LONG offset, bool type );
  extern LONG Pc2Snes( LONG offset, bool type );
  extern LONG FileSize( FILE *tf );
  extern void _freeTBL( );
  extern char *Text2Tbl( char *text, int size );  
  
  #include "DMDMain.h"
  #include "dos5x5.h"
  #include "Menu.h"  
  #include "TextEdit.h"
  #include "HexData.h"
  #include "DecompBlock.h"
  #include "kanaString.h"
  #include "kanaView.h"        

#endif




